package com.business_clean.viewmodel.request

import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import com.business_clean.app.App
import com.business_clean.app.config.Constant.PAGE_SIZE
import com.business_clean.app.network.NetUrl
import com.business_clean.data.mode.BaseDownLoadEntity
import com.business_clean.data.mode.project.ProjectManager
import com.business_clean.data.mode.roster.RosterEntity
import me.hgj.mvvmhelper.base.BaseViewModel
import me.hgj.mvvmhelper.ext.rxHttpRequest
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class DepartViewModel : BaseViewModel() {

    var staffManager = MutableLiveData<RosterEntity>()


    var downLoadEntity = MutableLiveData<BaseDownLoadEntity>()

    var allProjectManager = MutableLiveData<ProjectManager>()


    //获取离职人员列表
    fun getStaffList(page: Int, status: Int, role_id: Int, is_head_office: Int, project_uuid: String? = App.appViewModelInstance.projectInfo.value?.uuid) {
        rxHttpRequest {
            onRequest = {
                val hashMap = HashMap<String, String>()
                hashMap["page"] = "$page"
                hashMap["size"] = "50"
                hashMap["status"] = "$status"//状态 0全部 1在职 2离职
                hashMap["role_id"] = "$role_id"//1管理员 2项目负责人 3人事 4领班 5保洁 6大区经理
                hashMap["is_head_office"] = "$is_head_office"//是否总部员工0全部 1是 2否
                if (is_head_office != 1) {
                    if (!TextUtils.isEmpty(project_uuid)) {
                        hashMap["project_uuid"] = "$project_uuid"
                    } else {
                        hashMap["project_uuid"] = "${App.appViewModelInstance.projectInfo.value?.uuid}"
                    }
                }
                staffManager.value = RxHttp.get(NetUrl.GET_ROSTER_LIST)
                    .addAll(hashMap)
                    .toResponse<RosterEntity>().await()
            }
        }
    }


    //获取休息人员列表
    fun requestRestList(project_uuid: String, class_uuid: String) {
        rxHttpRequest {
            onRequest = {
                staffManager.value = RxHttp.get(NetUrl.GET_ROSTER_REST_LIST)
                    .add("project_uuid", project_uuid)
                    .add("class_uuid", class_uuid)
                    .toResponse<RosterEntity>().await()
            }
        }
    }


    /**
     * 操作类型 user档案 roster花名册 month_attendance月度考勤
     * 导出 excel
     */
    fun requestDownloadExcel() {
        rxHttpRequest {
            onRequest = {
                downLoadEntity.value = RxHttp.get(NetUrl.DOWNLOAD_EXPORT_EXCEL)
                    .add("op_type", "user")
                    .add("status", "2")//只要离职
                    .add("project_uuid", App.appViewModelInstance.projectInfo.value?.uuid)
                    .toResponse<BaseDownLoadEntity>().await()
            }
        }
    }


    /**
     * 获取用户的所有项目列表
     */
    fun getProjectMangerList(user_status: String) {
        rxHttpRequest {
            onRequest = {
                allProjectManager.value = RxHttp.get(NetUrl.GET_DEPART_GET_PROJECT_ALL)
                    .add("user_status", "$user_status")//user_status 1在职 2离职
                    .toResponse<ProjectManager>().await()
            }
        }
    }
}